<?php
class just4me extends MY_Controller{
	
	private $title;
	
	function __construct(){
		parent::__construct();
		$this->config->load("raw");
	}
	
	function index(){
		$this->dashboard();
	}
	
	function dashboard(){
		$this->title = "Admin";
		
		/*
		 * load header
		 */
		$header = $this->config->item("header");
		$header = $this->load->view("dashboard/admin/finalizeView/header",$header,true);
		
		/*
		 * load content
		 */
		$content = $this->config->item("content");
		$content['title'] = "Dashboard";
		$content['w_lpanel'] = "10%";
		$content['w_main'] = "80%";
		$content['w_rpanel_main'] = "50%";
		$content['w_lpanel_main'] = "50%";
		$query = array(
					'title'=>$content['title'],
				);
		$content['lpanel'] = $this->load->view('dashboard/admin/content/lpanel','',true);
		$content['main'] = $this->load->view('dashboard/admin/content/dashboard/main',$query,true);
		$content['lpanel_main'] = $this->load->view('dashboard/admin/content/dashboard/lpanel','',true);
		$content['rpanel_main'] = $this->load->view('dashboard/admin/content/dashboard/rpanel','',true);
		$content = $this->load->view("dashboard/admin/finalizeView/content",$content,true);
		
		/*
		 * load footer
		 */
		$footer = $this->config->item("footer");
		$footer = $this->load->view("dashboard/admin/finalizeView/footer",$footer,true);
		
		/*
		 * finalize view
		 */
		$jscript = array();
		$css = array('pages');
		$page = $this->config->item("page");
		$page['title'] = $page['title']." - ".$this->title;
		$this->finalizeViewAdmin(array(
			'title'=>$page['title'],
			'jscript_add'=>js_script($jscript),
			'css_add'=>css_script($css),
    		'jscript'=>js_script($page['jscript_default']),
    		'css'=>css_script($page['css_default']),
			'header'=>$header,
    		'content'=>$content,
			'footer'=>$footer,
			'layout_width'=>950,
			
		));
	}
	
	function login_admin(){
		
	}
	/*
	 *********************************************************************************************Load Page
	 */	
	function member(){
		$this->title = "Member";
		
		/*
		 * load header
		 */
		$header = $this->config->item("header");
		$header = $this->load->view("dashboard/admin/finalizeView/header",$header,true);
				
		/*
		 * load content
		 */
		$content = $this->config->item("content");
		$content['title'] = "Member";
		$content['w_lpanel'] = "10%";
		$content['w_main'] = "80%";
		$content['w_lpanel_main'] = "100%";
//		$content['w_rpanel_main'] = "50%";
		$query = array(
					'title'=>$content['title'],
				);
		$content['lpanel'] = $this->load->view('dashboard/admin/content/lpanel','',true);
		$content['main'] = $this->load->view('dashboard/admin/content/member/main',$query,true);
		$content['lpanel_main'] = $this->load->view('dashboard/admin/content/member/act/home','',true);
//		$content['rpanel_main'] = $this->load->view('dashboard/admin/content/pages/rpanel','',true);
		$content['bottom'] = $this->load->view('dashboard/admin/content/member/bottom',$query,true);
		$content = $this->load->view("dashboard/admin/finalizeView/content",$content,true);
		
		/*
		 * load footer
		 */
		$footer = $this->config->item("footer");
		$footer = $this->load->view("dashboard/admin/finalizeView/footer",$footer,true);
		
		/*
		 * finalize view
		 */
		$jscript = array();
		$css = array('pages','table');
		$page = $this->config->item("page");
		$page['title'] = $page['title']." - ".$this->title;
		$this->finalizeViewAdmin(array(
			'title'=>$page['title'],
			'jscript_add'=>js_script($jscript),
			'css_add'=>css_script($css),
    		'jscript'=>js_script($page['jscript_default']),
    		'css'=>css_script($page['css_default']),
			'header'=>$header,
    		'content'=>$content,
			'footer'=>$footer,
			'layout_width'=>950,
			
		));
	}
	
	function anggota(){
		$this->title = "Anggota";
		
		/*
		 * load header
		 */
		$header = $this->config->item("header");
		$header = $this->load->view("dashboard/admin/finalizeView/header",$header,true);
				
		/*
		 * load content
		 */
		$content = $this->config->item("content");
		$content['title'] = "Anggota";
		$content['w_lpanel'] = "10%";
		$content['w_main'] = "80%";
		$content['w_lpanel_main'] = "100%";
//		$content['w_rpanel_main'] = "50%";
		$query = array(
					'title'=>$content['title'],
				);
		$content['lpanel'] = $this->load->view('dashboard/admin/content/lpanel','',true);
		$content['main'] = $this->load->view('dashboard/admin/content/anggota/main',$query,true);
		$content['lpanel_main'] = $this->load->view('dashboard/admin/content/anggota/act/home','',true);
//		$content['rpanel_main'] = $this->load->view('dashboard/admin/content/pages/rpanel','',true);
		$content['bottom'] = $this->load->view('dashboard/admin/content/anggota/bottom',$query,true);
		$content = $this->load->view("dashboard/admin/finalizeView/content",$content,true);
		
		/*
		 * load footer
		 */
		$footer = $this->config->item("footer");
		$footer = $this->load->view("dashboard/admin/finalizeView/footer",$footer,true);
		
		/*
		 * finalize view
		 */
		$jscript = array('LightFace','LightFace.request');
		$css = array('pages','table','LightFace');
		$page = $this->config->item("page");
		$page['title'] = $page['title']." - ".$this->title;
		$this->finalizeViewAdmin(array(
			'title'=>$page['title'],
			'jscript_add'=>js_script($jscript),
			'css_add'=>css_script($css),
    		'jscript'=>js_script($page['jscript_default']),
    		'css'=>css_script($page['css_default']),
			'header'=>$header,
    		'content'=>$content,
			'footer'=>$footer,
			'layout_width'=>950,
			
		));
	}
	
	/*
	 *********************************************************************************************Add
	 */	
	function anggota_add(){
		$this->title = "Add Anggota";
		
		/*
		 * load header
		 */
		$header = $this->config->item("header");
		$header = $this->load->view("dashboard/admin/finalizeView/header",$header,true);
				
		/*
		 * load content
		 */
		$content = $this->config->item("content");
		$content['title'] = "Add Anggota";
		$content['w_lpanel'] = "10%";
		$content['w_main'] = "80%";
		$content['w_lpanel_main'] = "100%";
//		$content['w_rpanel_main'] = "50%";
		$query = array(
					'title'=>$content['title'],
				);
		$content['lpanel'] = $this->load->view('dashboard/admin/content/lpanel','',true);
		$content['main'] = $this->load->view('dashboard/admin/content/anggota/act/main',$query,true);
		$content['lpanel_main'] = $this->load->view('dashboard/admin/content/anggota/act/add','',true);
//		$content['rpanel_main'] = $this->load->view('dashboard/admin/content/pages/rpanel','',true);
		$content['bottom'] = $this->load->view('dashboard/admin/content/anggota/act/bottom',$query,true);
		$content = $this->load->view("dashboard/admin/finalizeView/content",$content,true);
		
		/*
		 * load footer
		 */
		$footer = $this->config->item("footer");
		$footer = $this->load->view("dashboard/admin/finalizeView/footer",$footer,true);
		
		/*
		 * finalize view
		 */
		$jscript = array('formcheck','datepicker','LightFace','LightFace.Request');
		$css = array('pages','table','formcheck','datepicker','LightFace');
		$page = $this->config->item("page");
		$page['title'] = $page['title']." - ".$this->title;
		$this->finalizeViewAdmin(array(
			'title'=>$page['title'],
			'jscript_add'=>js_script($jscript),
			'css_add'=>css_script($css),
    		'jscript'=>js_script($page['jscript_default']),
    		'css'=>css_script($page['css_default']),
			'header'=>$header,
    		'content'=>$content,
			'footer'=>$footer,
			'layout_width'=>950,
			
		));
	}
	
	function anggota_edit(){
		$this->load->model("anggotaMod");
		$id = $this->uri->segment(3,0);
		$this->title = "Edit Anggota";
		
		/*
		 * load header
		 */
		$header = $this->config->item("header");
		$header = $this->load->view("dashboard/admin/finalizeView/header",$header,true);
				
		/*
		 * load content
		 */
		$content = $this->config->item("content");
		$content['title'] = $this->title;
		$content['w_lpanel'] = "10%";
		$content['w_main'] = "80%";
		$content['w_lpanel_main'] = "100%";
//		$content['w_rpanel_main'] = "50%";
		$query = array(
					'title'=>$content['title'],
					'query'=>$this->anggotaMod->get($id)
				);
		$content['lpanel'] = $this->load->view('dashboard/admin/content/lpanel','',true);
		$content['main'] = $this->load->view('dashboard/admin/content/anggota/act/main',$query,true);
		$content['lpanel_main'] = $this->load->view('dashboard/admin/content/anggota/act/edit','',true);
//		$content['rpanel_main'] = $this->load->view('dashboard/admin/content/pages/rpanel','',true);
		$content['bottom'] = $this->load->view('dashboard/admin/content/anggota/act/bottom',$query,true);
		$content = $this->load->view("dashboard/admin/finalizeView/content",$content,true);
		
		/*
		 * load footer
		 */
		$footer = $this->config->item("footer");
		$footer = $this->load->view("dashboard/admin/finalizeView/footer",$footer,true);
		
		/*
		 * finalize view
		 */
		$jscript = array('formcheck','datepicker');
		$css = array('pages','table','formcheck','datepicker');
		$page = $this->config->item("page");
		$page['title'] = $page['title']." - ".$this->title;
		$this->finalizeViewAdmin(array(
			'title'=>$page['title'],
			'jscript_add'=>js_script($jscript),
			'css_add'=>css_script($css),
    		'jscript'=>js_script($page['jscript_default']),
    		'css'=>css_script($page['css_default']),
			'header'=>$header,
    		'content'=>$content,
			'footer'=>$footer,
			'layout_width'=>950,
			
		));
	}
	
	/*
	 *********************************************************************************************show
	 */
	function anggota_show(){
		$this->load->model("anggotaMod");

		$limit = $this->uri->segment(3,0);
		$offset = $this->uri->segment(4,0);
		$search = $this->uri->segment(5,0);
		
		if($search==""){
			$query = $this->anggotaMod->get_records($limit,$offset);
//			return $this->load->view("smp/showContent",array('query'=>$query));
			
		} else {
			//array('' => $id)
			$search =  str_replace("%20"," ",$search);
			$query = $this->anggotaMod->get_records_where($search,$limit,$offset);
//			$this->load->view("smp/showContent",array('query'=>$query));
		}
		return $this->load->view("dashboard/admin/content/anggota/act/show",array('query'=>$query));
	}
	
	/*
	 *********************************************************************************************Save
	 */	
	function anggota_save(){
		$this->load->model("anggotaMod");
		
		$identity = $this->input->post('identity');
		$name = $this->input->post('name');
		$place_of_birth = $this->input->post('place_of_birth');
		$birthday = date("Y-m-d",$this->input->post('birthday'));
		$gender = $this->input->post('gender');
		$email = $this->input->post('email');
		$website = $this->input->post('website');
		$phone = $this->input->post('phone');
		$address = $this->input->post('address');
		$region = $this->input->post('region');
		$city = $this->input->post('city');
		$blood = $this->input->post('blood');
		$education = $this->input->post('education');
		$work = $this->input->post('work');
		$skill = $this->input->post('skill');
		$achievment = $this->input->post('achievment');
		$id = $this->anggotaMod->generateID($name.$identity);
		
		$data = array(
					'id_anggota'=>$id,
					'identity'=>$identity,
					'name'=>$name,
					'place_of_birth'=>$place_of_birth,
					'birthday'=>$birthday,
					'gender'=>$gender,
					'email'=>$email,
					'website'=>$website,
					'phone'=>$phone,
					'address'=>$address,
					'region'=>$region,
					'city'=>$city,
					'blood'=>$blood,
					'education'=>$education,
					'work'=>$work,
					'skill'=>$skill,
					'achievment'=>$achievment
				);
//				echo $data;
		$this->anggotaMod->add($data);
		redirect('just4me/anggota/','refresh');
	} 
	
	/*
	 *********************************************************************************************Edit
	 */
	function anggota_update(){
		$this->load->model("anggotaMod");
		
		$id = $this->input->post('id_anggota');
		$identity = $this->input->post('identity');
		$name = $this->input->post('name');
		$place_of_birth = $this->input->post('place_of_birth');
		$birthday = $this->input->post('birthday');
		$gender = $this->input->post('gender');
		$email = $this->input->post('email');
		$website = $this->input->post('website');
		$phone = $this->input->post('phone');
		$address = $this->input->post('address');
		$region = $this->input->post('region');
		$city = $this->input->post('city');
		$blood = $this->input->post('blood');
		$education = $this->input->post('education');
		$work = $this->input->post('work');
		$skill = $this->input->post('skill');
		$achievment = $this->input->post('achievment');
		
		if($birthday==""){
			$data = array(
						'identity'=>$identity,
						'name'=>$name,
						'place_of_birth'=>$place_of_birth,
						'gender'=>$gender,
						'email'=>$email,
						'website'=>$website,
						'phone'=>$phone,
						'address'=>$address,
						'region'=>$region,
						'city'=>$city,
						'blood'=>$blood,
						'education'=>$education,
						'work'=>$work,
						'skill'=>$skill,
						'achievment'=>$achievment
					);
		} else {
			$birthday = date("Y-m-d",$this->input->post('birthday'));
			$data = array(
						'identity'=>$identity,
						'name'=>$name,
						'place_of_birth'=>$place_of_birth,
						'birthday'=>$birthday,
						'gender'=>$gender,
						'email'=>$email,
						'website'=>$website,
						'phone'=>$phone,
						'address'=>$address,
						'region'=>$region,
						'city'=>$city,
						'blood'=>$blood,
						'education'=>$education,
						'work'=>$work,
						'skill'=>$skill,
						'achievment'=>$achievment
					);
		}
		
		$this->anggotaMod->update($id,$data);
		redirect('just4me/anggota/','refresh');
	}
	
	/*
	 *********************************************************************************************Delete
	 */
	function anggota_delete(){
		$this->load->model("anggotaMod");
		$id = $this->uri->segment(3,0);
		$this->anggotaMod->remove($id);
		redirect('just4me/anggota/','refresh');
	}
	
}
